package gameEngine.com.state;

import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint.Style;
import android.view.KeyEvent;
import gameEngine.com.*;
import gameEngine.com.Actor.Actor;

public class StateHelp extends MainActivity {

	public static int currentPage = 0;
	public static int totalPage = 3;
	// align
	public static int HELP_POS_ARROW_LEFT_X = SCREEN_WIDTH / 2 - 110;
	public static int HELP_POS_ARROW_RIGHT_X = SCREEN_WIDTH / 2 + 50;
	public static int HELP_POS_ARROW_Y = SCREEN_HEIGHT - 70;

	public static synchronized void SendMessageStateHelp(int type) {

		switch (type) {
		case MESSAGE_CTOR:
			if (spriteIcon == null)
				spriteIcon = new Sprite("sprite/ui/icon.spr", true);
			if (logoimage == null)
				logoimage = loadImageFromAsset("image/logo.png");
			break;
		case MESSAGE_UPDATE:
			if (isTouchReleaseInRect(SCREEN_WIDTH - 70, SCREEN_HEIGHT - 70, 60, 60)) {
				if (!isGamePause) {
				changeState(STATE_SELECT_LEVEL);
				}else{
					changeState(STATE_IGM);
				}
			} else if (isTouchReleaseInRect(HELP_POS_ARROW_LEFT_X, HELP_POS_ARROW_Y, 60, 60)) {
				currentPage--;
				if (currentPage < 0)
					currentPage = totalPage - 1;

			} else if (isTouchReleaseInRect(HELP_POS_ARROW_RIGHT_X, HELP_POS_ARROW_Y, 60, 60)) {
				currentPage++;
				if (currentPage >= totalPage)
					currentPage = 0;
			}
			break;
		case MESSAGE_PAINT:
			mainCanvas.drawColor(Color.BLACK);
			Matrix matrix = new Matrix();
			if (!isGamePause) {
				mainCanvas.drawBitmap(splashImage, matrix, null);
				mainCanvas.drawColor(0xAd222222);
			} else {
				StateGameplay.SendMessageGameplay(MESSAGE_PAINT);
				mainCanvas.drawColor(0xFd222222);
			}
			matrix.postScale(0.8f, 0.8f);
			matrix.postTranslate(3, 30);
			mainCanvas.drawBitmap(logoimage, matrix, null);

			switch (currentPage) {
			case 0:
				fontsmall.drawString(mainCanvas, mainGameLib.getResources().getString(R.string.STRING_HELP1), SCREEN_WIDTH >> 1, (SCREEN_HEIGHT >> 1) -60, 400, 2);
				break;
			case 1:
				fontsmall.drawString(mainCanvas, mainGameLib.getResources().getString(R.string.STRING_HELP2), SCREEN_WIDTH >> 1, (SCREEN_HEIGHT >> 1) - 60, 400, 2);
				break;
			case 2:
				fontsmall.drawString(mainCanvas, mainGameLib.getResources().getString(R.string.STRING_HELP3), SCREEN_WIDTH >> 1, (SCREEN_HEIGHT >> 1) - 60, 400 , 2);
				break;
			default:
				break;
			}
			fontsmall.drawString(mainCanvas, "" + (currentPage + 1) + " / " + totalPage + "", SCREEN_WIDTH >> 1, SCREEN_HEIGHT - 50, 2);
			spriteIcon.drawAFrame(mainCanvas, 0, HELP_POS_ARROW_LEFT_X, HELP_POS_ARROW_Y); // arrow
																							// left
																							// button
			spriteIcon.drawAFrame(mainCanvas, 1, HELP_POS_ARROW_RIGHT_X, HELP_POS_ARROW_Y);// arrow
																							// right
																							// button
			spriteIcon.drawAFrame(mainCanvas, 4, SCREEN_WIDTH - 70, SCREEN_HEIGHT - 70);// 4
																						// =
																						// back
																						// button

			break;
		case MESSAGE_DTOR:

			break;
		}
	}
}
